import axios from 'axios'

const http = axios.create()

http.interceptors.request.use((config) => {
  let user = localStorage.getItem('userInfo')
  config.headers.token = user ? JSON.parse(user).token : ''
  return config
})

http.interceptors.response.use((res) => {
  if (res.status === 200) {
    return res.data
  } else {
    return Promise.reject(res.statusText)
  }
}, err => {
  return Promise.reject(err.message)
})

export default http
